package org.dynoproxy.test.store;

import java.util.List;


public class InvoiceCalculator {
	private ProductService productService;
	private ShippingCalculator shippingCalculator;
	private AccountService accountService;
	
	public AccountService getAccountService() {
		return accountService;
	}
	public void setAccountService(AccountService accountService) {
		this.accountService = accountService;
	}
	public ProductService getProductService() {
		return productService;
	}
	public void setProductService(ProductService productService) {
		this.productService = productService;
	}
	public ShippingCalculator getShippingCalculator() {
		return shippingCalculator;
	}
	public void setShippingCalculator(ShippingCalculator shippingCalculator) {
		this.shippingCalculator = shippingCalculator;
	}
	
	
	public Invoice calculate(long accountId, List<Long> productList){
		Invoice invoice = new Invoice();
		double totalWeight = 0;
		double totalCost = 0;
		Account account = accountService.getAccount(accountId);
		for (Long prodId : productList){
			Product p = productService.getProduct(prodId);
			totalWeight += p.getWeight();
			totalCost += p.getPrice();
		}
		double shippingCharge = shippingCalculator.calculateShippingCharge(account.getZipCode(), totalWeight);
		invoice.setShippingCharges(shippingCharge);
		invoice.setTotal( totalCost + shippingCharge);
		invoice.setProductChanges(totalCost);
		return invoice;
	}
	
}
